<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>改变背景颜色</title>
    <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
    <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
    <style>
        .a{
            background-color: blueviolet;
            width: 0;
            display: none;
        }
    </style>
</head>
<body>
<div id="app">

</div>
</body>
</html>
<script type="text/babel">
    let app=document.getElementById('app');
    class Child extends React.Component{
        constructor(props) {
            super(props);
            this.state={
                bc:"red",
            }
        }
        render() {
            return <div>
                <h2 onClick={this.oneclick.bind(this)} style={{backgroundColor:this.state.bc}}>点击变色</h2>
            </div>
        }
    //    函数
        oneclick(){
            console.log(this.state.bc)
this.setState({bc:`rgb(${Math.floor(Math.random()*256)},${Math.floor(Math.random()*256)},${Math.floor(Math.random()*256)})`})
        }
    }
    ReactDOM.render(<Child/>,app)
</script>